<template>
  <div>
    <h2>拉平数组</h2>
    <div>
      结果：{{ result }}
    </div>
    <h2>比较对象</h2>
    <div>
      结果：{{ flag }}
    </div>
    <ul @click="handleAll">
      <li v-for="n in 90" :key="n">{{ n }}</li>
    </ul>
  </div>
</template>

<script>
import { flattenArray } from 'utils/tools.js'
export default {
  data () {
    return {
      result: '',
      flag: ''
    }
  },
  created () {
    this.handle()
    this.handleCompareObj()
  },
  methods: {
    handle () {
      let arr = [1, [2, ['3', '{a: 4}', [4]]], 5, [6, [7]]]
      this.result = flattenArray(arr)
    },
    flattenArray (arr) { // 拉平数组
      let a = arr.join(',').split(',') // 取巧，改变类型
      return a
    },
    handleCompareObj () {
      let obj = {
        name: 'zz'
      }
      let obj2 = {
        name: 'zz'
      }
      this.flag = this.compareObj(obj, obj2)
    },
    compareObj (a, b) {
      return JSON.stringify(a) === JSON.stringify(b)
    },
    handleAll (e) {
      let type = e.target.innerHTML
      console.log(type)
    }
  }
}
</script>
